<%inherit file="base.html"/>
<%block name="content">
<link href="${STATIC_URL}app_perm/css/dataTables.bootstrap.css" rel="stylesheet"/>
<script src="${STATIC_URL}app_perm/js/jquery-1.10.2.min.js"></script>
<script src="${STATIC_URL}app_perm/js/jquery.dataTables.js"></script>


<link href="${STATIC_URL}app_perm/css/select2.css" rel="stylesheet">
    <!-- content start -->
    <div class="king-layout1-content container">
        <section class="king-content-header king-info-header mb20 pb10 mt20">
            <h4 class="pull-left">
                App: <code>【${app_name}】</code>权限拥有者列表
            </h4>
        </section>


        <div role="alert" class="alert alert-success">
            <strong>提示: </strong> 用户对应app的权限控制 (用户分配到的app将会有完全访问控制权限);<br>默认<code>超级用户</code>可操作访问所有App.</b>
        </div>

        <div class="row">
            <div class="col-sm-12">
                    <div class="king-block-content">

                           <table id="table2_demo2" class="table table-bordered table-hover">
                                            <thead>
                                                <tr>
                                                   <th >用户</th>
                                                   <th>操作</th>
                                                </tr>
                                            </thead>
                                                 <tbody>
                                                     % for each_data in app_users:
                                                        <tr>
                                                            <td>${each_data}</td>
                                                            <td><input type="button" class="king-btn king-danger" name="${each_data}" onclick=del_db(this) value="删除该用户"></td>
                                                        </tr>
                                                    % endfor
                                                </tbody>
                                                <tfoot >
                                            <tr>
                                        </tr>
                                </tfoot>
                            </table>
                        <input type="button" class="king-btn king-success" onclick=add_users() value="添加一个用户">
                    </div>

            </div>
        </div>

<!--
        <div class="row">

            <div class="col-sm-6 chart-one">
                <div class="king-block king-block-bordered">
                    <div class="king-block-header  king-gray-light">
                        <ul class="king-block-options">
                            <li>
                                <button type="button"><i class="fa fa-cog"></i></button>
                            </li>
                        </ul>
                        <h3 class="king-block-title f12">密码破解拦截<span class="text-muted">(单位/次)</span></h3>
                    </div>
                    <div class="king-block-content">
                        <div class="chart-content" id="chartB" style="overflow:hidden;">
                            <div class="tc bc" style="margin-top:200px;">
                                <img src="https://magicbox.bkclouds.cc/static_api/v3/components/loading1/images/loading_2_24x24.gif"> 数据加载中,请稍后...
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-sm-6 chart-one">
                <div class="king-block king-block-bordered">
                    <div class="king-block-header  king-gray-light">
                        <ul class="king-block-options">
                            <li>
                                <button type="button"><i class="fa fa-cog"></i></button>
                            </li>
                        </ul>
                        <h3 class="king-block-title f12">网站Web攻击防护<span class="text-muted">(单位/次)</span></h3>
                    </div>
                    <div class="king-block-content">
                        <div class="chart-content" id="chartD" style="overflow:hidden;">
                            <div class="tc bc" style="margin-top:200px;">
                                <img src="https://magicbox.bkclouds.cc/static_api/v3/components/loading1/images/loading_2_24x24.gif"> 数据加载中,请稍后...
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
-->
    </div>




        <!-- content end -->
    <!-- 表格分页功能 -->
<script>
  $(function () {
    var language = {
      search: '搜索：',
      lengthMenu: "每页显示 _MENU_ 记录",
      zeroRecords: "没找到相应的数据！",
      info: "分页 _PAGE_ / _PAGES_",
      infoEmpty: "暂无数据！",
      infoFiltered: "(从 _MAX_ 条数据中搜索)",
      paginate: {
        first: '首页',
        last: '尾页',
        previous: '上一页',
        next: '下一页'
      }
    };
    $('#table2_demo2').dataTable({
      paging: true, //隐藏分页
      ordering: false, //关闭排序
      info: false, //隐藏左下角分页信息
      searching: true, //关闭搜索
      pageLength : 10, //每页显示几条数据
      lengthChange: true, //不允许用户改变表格每页显示的记录数
      language: language, //汉化

    } );
  });
</script>

<script>
  function del_db(_this){
    var app_user = $(_this).attr('name');
    var app_code = "${app_code}"
    swal(app_user)
     swal({
                  title: "您确定要删除该用户?",
                  //text: "删除后将无法恢复，请谨慎操作！",
                  type: "warning",
                  showCancelButton: true,
                  showLoaderOnConfirm: true,
                  confirmButtonColor: "#DD6B55",
                  confirmButtonText: "是的，删除: "+ app_user,
                  cancelButtonText: "我在想想吧...",
                  closeOnConfirm: false,
                  closeOnCancel: true  //关闭取消后还弹出让你确认的效果提示
                },
                  function(isConfirm){
                  if (isConfirm) {    // 如果确认就会去携带者hostname去后台处理
                    $.ajax ({
                            type:'post',
                            url:"${SITE_URL}del_users/?app_code=" + app_code + "&app_user=" + app_user,
                            success:function(res){   //将处理的结果进行判断，根据执行失败，成功现实的提示不同的内容
                                if (res.result) {
                                    swal(res.messages, "","success");
                                    $(_this).parents("tr").remove();
                                }
                                else {
                                    swal(res.messages, "", "error");
                                }
                            }
                        });
                     }
                });
  }
</script>

<script>
  function add_users(){
      var x=document.getElementById('table2_demo2').insertRow(1);
      var y=x.insertCell(0);
      var z=x.insertCell(1);
      y.innerHTML="<input id='input_text1' type='text' value='' style='width:100%' class='form-control'/>";
      z.innerHTML="<input type='button' class='king-btn king-success' name='' onclick=save(this) value='保存'>";
    }
  function save(_this) {
    var app_user = $("#input_text1").val();
    var app_code = "${app_code}"
        $.ajax ({
              type:'post',
              url:"${SITE_URL}add_users/?app_code=" + app_code + "&app_user=" + app_user,
              success:function(res){   //将处理的结果进行判断，根据执行失败，成功现实的提示不同的内容
                  if (res.result) {
                      swal(res.messages, "","success");

                  }
                  else {
                      swal(res.messages, "", "error");
                  }
              }
          });
       }
</script>
</%block>
